home *** CD-ROM | disk | FTP | other *** search
/ MPEG Toolkit / MPEG Toolkit.iso / dos / mpegstat / filter.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-01  |  4.9 KB  |  228 lines

  1. /* MPEGSTAT - analyzing tool for MPEG-I video streams
  2.  * 
  3.  * Technical University of Berlin, Germany, Dept. of Computer Science
  4.  * Tom Pfeifer - Multimedia systems project - pfeifer@fokus.gmd.de
  5.  *
  6.  * Jens Brettin, Harald Masche, Alexander Schulze, Dirk Schubert
  7.  *
  8.  * ---------------------------
  9.  *
  10.  * Copyright (c) 1993 Technical University of Berlin, Germany
  11.  * All rights reserved.
  12.  *
  13.  * ---------------------------
  14.  *
  15.  * Permission to use, copy, modify, and distribute this software and its
  16.  * documentation for any purpose, without fee, and without written agreement is
  17.  * hereby granted, provided that the above copyright notices and the following
  18.  * two paragraphs appear in all copies of this software.
  19.  * 
  20.  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA 
  21.  * or the Technical University of Berlin BE LIABLE TO ANY PARTY FOR
  22.  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  23.  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  24.  * CALIFORNIA or the Technical University of Berlin HAS BEEN ADVISED OF THE 
  25.  * POSSIBILITY OF SUCH DAMAGE.
  26.  * 
  27.  * THE UNIVERSITY OF CALIFORNIA and the Technical University of Berlin 
  28.  * SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
  29.  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30.  * PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE 
  31.  * UNIVERSITY OF CALIFORNIA and the Technical University of Berlin HAVE NO 
  32.  * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, 
  33.  * OR MODIFICATIONS.
  34.  */
  35.  
  36. /*
  37.  * analyzing routines
  38.  */
  39.  
  40. #include <stdio.h>
  41. #include "video.h"
  42.  
  43. #define max(a,b)  (a>b?a:b)
  44. #define MAXPIC    2000
  45.  
  46. static int bcounter;            /* counter for bytes read */
  47. static char frame_seq[MAXPIC];        /* frame types as displayed */
  48.  
  49. void byte_count(num)
  50. int num;
  51. {
  52.     bcounter += num;
  53. }
  54.  
  55. int print_bytes()
  56. {
  57.     return bcounter;
  58. }
  59.  
  60. int mvstat (int value, int mode)
  61. {
  62.     static int max_horizontal_f = 0, max_vertical_f = 0;
  63.     static int  max_horizontal_b = 0, max_vertical_b = 0;
  64.     static int ave_h_b = 0, ave_h_f = 0, ave_v_b = 0, ave_v_f = 0;
  65.     static int qscale;
  66.     static int count_h_b = 0, count_h_f = 0, count_v_b = 0, count_v_f = 0;
  67.     int *ip;
  68.  
  69.     switch (mode) {
  70.         case 0:
  71.             ip = &max_horizontal_f;
  72.             if(value != 0) {    
  73.                 count_h_f++;
  74.                    ave_h_f += abs(value);
  75.             }
  76.             break;
  77.         case 1:
  78.             ip = &max_vertical_f;
  79.             if(value != 0) {
  80.                 count_v_f++;
  81.                 ave_v_f += abs(value);
  82.             }
  83.             break;
  84.         case 2:
  85.             ip = &max_horizontal_b;
  86.             if(value != 0) {
  87.                 count_h_b++;
  88.                 ave_h_b += abs(value);
  89.             }
  90.             break;
  91.         case 3:
  92.             ip = &max_vertical_b;
  93.             if(value != 0) {
  94.                 count_v_b++;
  95.                 ave_v_b += abs(value);
  96.             }
  97.             break;
  98.         case 4:
  99.             ip = &qscale;
  100.             break;
  101.         case 5:
  102.             return max_horizontal_f;
  103.         case 6:
  104.             return max_vertical_f;
  105.         case 7:
  106.             return max_horizontal_b;
  107.         case 8:
  108.             return max_vertical_b;
  109.         case 9:
  110.             return qscale;
  111.         case 10 :
  112.                 if (count_h_f > 0)
  113.                 return( ave_h_f / count_h_f);
  114.             else return 0;
  115.         case 11 :
  116.             if (count_v_f > 0)
  117.                 return( ave_v_f / count_v_f);
  118.             else return 0;
  119.         case 12 :
  120.             if (count_h_b > 0)
  121.                 return( ave_h_b / count_h_b);
  122.             else return 0;
  123.         case 13 :
  124.             if (count_v_b > 0)
  125.                 return( ave_v_b / count_v_b);
  126.             else return 0;
  127.  
  128.     }
  129.     *ip = max (*ip, abs (value));
  130.     return 0;
  131. }
  132.  
  133.  
  134. /*
  135.  * printtype prints the frame type during data parsing.
  136.  */
  137.  
  138. printtype(VidStream *vs)
  139. {
  140.  
  141.     static int first_time = 1;
  142.  
  143.     if(first_time) {
  144.         printf("Frame sequence as found while parsing:\n");
  145.         first_time = 0;
  146.     }
  147.  
  148.     switch (vs->picture.code_type) {
  149.         case B_TYPE:
  150.             printf("B");
  151.             break;
  152.         case P_TYPE:
  153.             printf("P");
  154.             break;
  155.         case I_TYPE:
  156.             printf("I");
  157.             break;
  158.         default:
  159.             printf("-unknown-");
  160.     }
  161.     fflush(stdout);
  162. }
  163.  
  164. /*
  165.  * display some frame attributes during output time
  166.  */
  167.  
  168. ShowOutputVal(VidStream *vs)
  169. {
  170.     static i = 0;
  171.  
  172.     if(i >= MAXPIC -1)
  173.         return;
  174.  
  175.     switch (vs->picture.code_type) {
  176.         case B_TYPE:
  177.             frame_seq[i++] = 'B';
  178.             break;
  179.         case P_TYPE:
  180.             frame_seq[i++] = 'P';
  181.             break;
  182.         case I_TYPE:
  183.             frame_seq[i++] = 'I';
  184.             break;
  185.         default:
  186.             printf("-unknown-");
  187.     }
  188.  
  189.     frame_seq[i] = '\0';
  190.  
  191. }
  192.  
  193.  
  194. Search4Pattern() 
  195. {
  196.     char tmpbuf[MAXPIC];
  197.  
  198.     char *s;
  199.     int i = 0;
  200.     s = frame_seq;
  201.  
  202.     printf("\nSearching for constant frame type sequence...");
  203.     while(*s != 'I' )  
  204.         ++s ;
  205.  
  206.     tmpbuf[i++] = *s++;
  207.  
  208.     while ((tmpbuf[i++] = *s) != 'I' )
  209.          ++s;
  210.     tmpbuf[i - 1] = '\0';
  211.  
  212.         if(!memcmp(s, tmpbuf,--i)) 
  213.         if(!memcmp(s + i, tmpbuf, i))
  214.             if(!memcmp(s + 2*i, tmpbuf, i)) {
  215.                 printf("pattern detected: %s\n\n", tmpbuf);    
  216.                 return(1);
  217.             }
  218.     printf("No constant frame type pattern found.\n");
  219.     return(0);
  220. }
  221.  
  222. ShowFrameSeq()
  223. {
  224.     printf("\n\nFrame sequence as to be displayed: \n%s\n\n", frame_seq);
  225.  
  226.     Search4Pattern();
  227. }
  228.